package com.sj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sj.entity.Tag;
import com.sj.mapper.TagMapper;
import com.sj.service.TagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-07-30
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public IPage<Tag> listTagByPage(Integer userId, Integer current, Integer size) {
        IPage<Tag> page = new Page<Tag>(current, size);
        IPage<Tag> tagPageInfo = null;
        if (userId == null) {
            tagPageInfo = tagMapper.selectPage(page, new QueryWrapper<Tag>().groupBy("tag_name"));
        }
        if (userId != null) {
            tagPageInfo = tagMapper.selectPage(page, new QueryWrapper<Tag>().eq("user_id", userId));
        }
        return tagPageInfo;
    }

    @Override
    public List<Tag> getTagListByBlogId(Integer blogId) {
        return tagMapper.getTagListByBlogId(blogId);
    }

    @Override
    public Integer getCountTagBindBlog(Integer id) {

        return tagMapper.getCountTagBindBlog(id);
    }
}
